from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from collections import OrderedDict
from django.utils.translation import gettext_lazy as _

class MyPagination(PageNumberPagination):
    page_size = 10
    max_page_size = 100
    page_size_query_param = 'page_size'
    page_query_param = 'page'

    page_query_description = _('页数')
    page_size_query_description = _('每页数量')

    # 自定义响应内容
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('count', self.page.paginator.count),
            # ('next', self.get_next_link()),
            # ('previous', self.get_previous_link()),
            ('data', data),
            ('code', 200),
            ('message', 'success')
        ]))


    '''
        age_query_param：表示url中的页码参数
		page_size_query_param：表示url中每页数量参数
		page_size：表示每页的默认显示数量
		max_page_size：表示每页最大显示数量，做限制使用，避免突然大量的查询数据，数据库崩溃
    '''